<template>
  <div>
    <Drawer ref="DrawerRef" title="设置商品详情" @submit="submit">
      <Editor v-model="form.content" />
    </Drawer>
  </div>
</template>
<script setup>
import { ref, reactive } from "vue";
import { readGoods, editGoods } from "@/api/goods";
import { Toast } from "@/utils/utils.js";
import Drawer from "@/components/Drawer/index.vue";
import Editor from "@/components/Editor/index.vue";

let DrawerRef = ref(null);
const form = reactive({
  content: "",
});
let currentId = ref("");
// 打开
const open = (row) => {
  DrawerRef.value.openDrawer();
  currentId.value = row.id;
  readGoods(row.id)
    .then((res) => {
      form.content = res.data.content;
    })
    .catch((err) => {
      console.log(err);
    });
};
let emit = defineEmits(["submit"]);
const submit = () => {
  editGoods(currentId.value, {
    content: form.content,
  }).then((res) => {
    if (res.status === 200) {
      Toast("设置商品详情成功");
      DrawerRef.value.closeDrawer();
      emit("submit");
    }
  });
};
const handleClose = () => {
  DrawerRef.value.closeDrawer();
};
defineExpose({
  open,
});
</script>
